<?php
/**
 * Created by PhpStorm.
 * User: xiao
 * Date: 2017/6/15
 * Time: 上午10:00
 */

namespace app\domain;


use app\src\base\helper\PageHelper;
use app\src\insurance\action\InsuranceAction;
use app\src\insurance\logic\InsuranceApplyLogic;
use app\src\insurance\logic\InsuranceLogic;
use app\src\insurance\logic\InsuranceOrderInfoLogic;
use app\src\seller\logic\SellerLogic;

class InsuranceDomain extends BaseDomain
{
    /**
     * 添加车险申请
     */
    public function addApply()
    {
        $this->checkVersion(100);
        $uid=$this->_post('uid','','缺少UID');
        $insurance_id=$this->_post('insurance_id','','缺少保险id');
        $json['name']=$this->_post('name','','缺少姓名');
        $json['car_code']=$this->_post('car_code','','缺少车牌号');
        $json['mobile']=$this->_post('mobile','','缺少手机');
        $json['id_front']=$this->_post('id_front','','缺少身份正面');
        $json['id_back']=$this->_post('id_back','','缺少身份背面');
        $json['driving_license_front']=$this->_post('driving_license_front','','缺少驾驶证正面');
        $json['driving_license_back']=$this->_post('driving_license_back','','缺少驾驶证背面');
        $json['three_respons_insurance']=$this->_post('three_respons_insurance','','缺少第三方责任');
        $json['annual_survey']=$this->_post('annual_survey','','缺少年检');
        $json['his_insurance']=$this->_post('his_insurance','');
        $json=json_encode($json);
        $entity = [
            'uid' => $uid,
            'insurance_id' =>$insurance_id,
            'apply_info' =>$json,
        ];
        $result = (new InsuranceApplyLogic())->addApply($entity);
        $this->returnResult($result);
    }


    /*
     * 获取车险列表
     */
    public function getList(){
        $this->checkVersion(100);

        $list=(new InsuranceLogic())->getList();

        $this->returnResult($list);
    }
    public function getInsuranceOrderInfo(){

        $this->checkVersion(100);

        $apply_id=$this->_post('id','','缺少保险申请id');
        $result = (new InsuranceOrderInfoLogic())->getInfo(['apply_id'=>$apply_id,'status'=>0]);


        if($result['status']){
            $payinfo = $result['info']['pay_info'];
            $payinfo = json_decode($payinfo, true);
            $this->apiReturnSuc($payinfo);
        }else{
            $this->apiReturnErr($result['info']);
        }

    }

    /*
     * 上传支付截图
     */
    public function addPayImg(){
        $this->checkVersion(100);

        $apply_id=$this->_post('id','','缺少保险申请id');
        $img=$this->_post('img','','缺少支付截图');

        $result=(new InsuranceAction())->payImg($apply_id,$img);
        if($result['status']){
            $this->apiReturnSuc($result['info']);
        }else{
            $this->apiReturnErr($result['info']);
        }

    }


    /*
     * 用户获取自己的支付申请
     */
    public function userApplys(){
        $this->checkVersion(100);
        $uid=$this->_post('uid','','缺少uid');
        $apply_id=$this->_post('apply_id','');
        $result=(new InsuranceAction())->UserList($uid,$apply_id);
        $this->returnResult($result);
    }


}